package com.example.shaoying.yuejian.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.shaoying.yuejian.R;
import com.example.shaoying.yuejian.model.ClubeModel;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by ShaoYing on 2017/10/18.
 */

public class ActivityJoinActivity extends AppCompatActivity {
    private ImageView add,jianshao;
    private Button jiesuan;
    private TextView Ttrainname,Trealname,Tsum, Tphone,Tprice,number;
    private String  participantname;//真实姓名
    private String train_id;// /培训ID
    private String participanttel;//联系方式
    private String adultnum;//票数量
    private String  paytype;//支付类型1微信2支付宝/
    private String pay;//支付金额/
    private String paynotice;//支付后唯一标识/
    private String userId;//为用户id
    private String sessionId;
    private SharedPreferences sp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_join);
       /* init();
        getdata();
        addnumber();
       event();*/
    }
    /*private void event() {
        jiesuan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClubeModel model=new ClubeModel();
                Call<String> call=model.joinTrain(participantname,train_id,participanttel, adultnum, paytype, pay, paynotice,userId,sessionId);
                call.enqueue(new Callback<String>() {
                    @Override
                    public void onResponse(Call<String> call, Response<String> response) {
                        String success=response.body().toString();
                        Toast.makeText(ActivityJoinActivity.this,success, Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFailure(Call<String> call, Throwable t) {

                    }
                });
            }
        });
    }*/

   /* private void init()
    {
        Ttrainname=(TextView)findViewById(R.id.Ttrainname);
        Tprice=(TextView)findViewById(R.id.Tprice);
        Trealname=(TextView)findViewById(R.id.Trealname);
        number=(TextView)findViewById(R.id.number);
        Tsum=(TextView)findViewById(R.id.Tsum);
        Tphone=(TextView)findViewById(R.id.Tphone);
        jiesuan=(Button)findViewById(R.id.jiesuan);
        jianshao= (ImageView) findViewById(R.id.jianshao);
        add= (ImageView) findViewById(R.id.add);
    }
    private  void getdata(){
        sp = getSharedPreferences("login_uid", Context.MODE_PRIVATE);
        participantname=Ttrainname.getText().toString();
        participanttel=Tphone.getText().toString();

        pay=Tsum.getText().toString();
        paytype="1";
        adultnum=number.getText().toString();
        Intent intent=getIntent();
        train_id=intent.getStringExtra("train_id");
        Ttrainname.setText(intent.getStringExtra("train_name"));
        Ttrainname.setText(intent.getStringExtra("train_name"));
        Tprice.setText(intent.getStringExtra("train_price")+"/人");
        int price=Integer.parseInt(intent.getStringExtra("train_price"));
        int num=Integer.parseInt(adultnum);
        int all=price*num;
        Tsum.setText("合计："+all);
        paynotice="shaoying";
        sessionId=sp.getString("sessionId","");
        userId=sp.getString("userId","");
    }
    private void addnumber() {


        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               int num=Integer.parseInt(number.getText().toString());
                num++;
                number.setText(num+"");
                getdata();

            }
        });
        jianshao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int num=Integer.parseInt(number.getText().toString());
                num--;
                if (num > 0){
                    number.setText(num+"");
                    getdata();
                }
                else
                {  Toast.makeText(ActivityJoinActivity.this, "购买数量大于0", Toast.LENGTH_SHORT).show();
                    number.setText("1");
                }

            }

        });

    }*/


}
